home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
sound
/
sample20.zip
/
SAMPLASM.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-05-20
|
23KB
|
769 lines
;
; SAMPLASM.ASM
; ------------
;
; One voice sampler playback system using fractional addition 16/3/89
;
; with optional patch to drive PC speaker using PWM
;
; For use with SAMPLER.PAS V2
;
;
;
;
; (C) Copyright 1989 by Rowan McKenzie
;
; You may copy these files or use the source code only
; for non-profit purposes. Please contact me if you wish to use any
; part of the package for commercial purposes.
;
;
; Rowan McKenzie
; 35 Moore Ave,
; Croydon 3136
; Vic Australia
;
;
;
; This code provides the assembler section of SAMPLER.PAS
;
; This version uses the system timer for sample timing, and is therefore
; clock speed independent, although the CPU must be able to keep up with
; the interrupt rate (20kHz!).
;
;
;
; Notes:
; ------
;
; To assemble the D to A converter version, set pwm equ false
;
; To assemble the PWM version, set pwm equ true
;
; The D/A version uses the system timer (at 20kHz) to synchronise output
; samples (and to make the code clock speed independent)
;
; The PWM version uses the system timer in the same way, but triggers the
; speaker timer channel as a monostable whose pulse length is proportional
; to the sample value. Note that time constants are all scaled assuming
; 20kHz sample rate. If another sample rate is used, these will need to be
; recalculated. Also, faster sampling rates mean lower effective resolution
; from the one shot because it is clocked at a fixed frequency. The current
; setup gives the equivalent of a 6 bit d/a converter (I know that's not
; very good, but it's better than most PC speakers can justify!)
;
;
;
; Variables defined in Pascal source:
; -----------------------------------
;
; release is a boolean variable indicating whether key releases should
; terminate sound playback
;
; loop is a boolean variable indicating that the loop section of the sample
; should be played continuously after playback is complete
;
; daout is an integer variable containing the d/a converter port
; (for D/A version)
;
; increment is an integer variable containing a fractional increment constant which
; determines the pitch of the note to be played
;
; bufloop is an integer variable containing the offset of the start of the
; loop section
;
; bufend is an integer variable containing the offset of the end of the sample
; (for when the sample code is implemented)
;
; bufstart is an integer variable containing the offset of the start of the
; sample
;
; kbdmode is a boolean variable indicating whether keyboard service routine
; should pass control to bios (false) or handle the key itself (true)
;
; kbdflag is a byte variable to indicate a key has been pressed during replay
;
; keyval is a byte variable which will contain the scan code of a key pressed
; during replay
;
; tconstant is a byte variable which sets the system timer rate (20kHz)
;
; timer is a boolean variable which indicates the timer should be used
; to determine how long notes should last
;
; tinterval is an integer variable indicating how long a note should be
; played for (no. interrupts mod modulus)
;
; modulus is a byte variable which determines after how many interrupts the
; tinterval counter should be decremented
;
; song is a boolean variable indicating whether a song is being played
;
; trigger is an integer variable describing the minimum input level required
; to begin sampling
;
page 255,132
title sampler asm module
; ===== Equates =====
true equ 1
false equ 0
pwm equ false ;pwm version if true else d/a version
tdelay equ 2 ;delay constant between samples while
; waiting for trigger
lshiftr equ 170 ;scan code for left shift release
rshiftr equ 182
tccont equ 43h ;control reg of 8253 timer chip
tccount equ 42h ;counter reg 2 (speaker)
speaker equ 97 ;speaker port for PWM version
data segment word public
;
; data
;
extrn tconstant:word,keyval:word,kbdflag:word,bufstart:word
extrn bufend:word,bufloop:word,increment:word,daout:word,loop:word
extrn release:word,timer:word,tinterval:word,modulus:word,song:word
extrn trigger:word,kbdmode:word,quickexit:word,buffer:word
extrn bufferw:word,bufflen:word
sysold dd ? ;temp storage for old system int vector
sptemp dw ? ;storage for sp for quick exit
duration dw ? ;duration counter
modul db ? ;local modulus counter
data ends
code segment byte public
assume cs:code,ds:data
public restore,sample,initial,replay,replayt,scalewave,echo
kbdold dd ? ;temp storage for old kbd int vector
dstemp dw ? ;holds ds incase it's needed
;************************************************************
;
; Restore - restore int vectors and exits
;
;************************************************************
restore proc near
cli ;restore old kbd interrupt
push ds
mov dx,word ptr cs:[kbdold]
mov ds,word ptr cs:[kbdold+2]
mov ax,2509h
int 21h ;restore old kbd vector
pop ds
if pwm
mov al,0b6h
out tccont,al ;change timer to square wave gen mode
in al,speaker
and al,0fch
out speaker,al ;speaker one shot disable
endif
sti
ret
restore endp
;***********************************************************************
;
; Initialise - save int vector contents, replace with my version
;
;***********************************************************************
initial proc near
cli
mov cs:[dstemp],ds
mov ax,3509h ;get old kbd int
int 21h
mov word ptr cs:[kbdold],bx ;save it
mov word ptr cs:[kbdold+2],es
mov dx,offset kbdint
push ds
mov ax,cs
mov ds,ax
mov ax,2509h
int 21h ;replace with mine
pop ds
mov byte ptr [kbdflag],0 ;no key activity
if pwm
mov al,0b6h
out tccont,al ;change timer to square wave gen mode
mov al,byte ptr[tconstant]
shr al,1
out tccount,al ;produce mean equivalent dc voltage
xor al,al
out tccount,al
in al,speaker
or al,3
out speaker,al ;speaker one shot enable
else
mov dx,[daout]
mov al,127
out dx,al
endif
sti
ret
initial endp
;******************************************************************************
;
; Sample data from A/D port
;
;******************************************************************************
sample proc near
cli
in al,21h
or al,98h ;disable comms, printer interrupts
out 21h,al
mov ax,3508h
int 21h ;get system timer vector
mov word ptr [sysold],bx
mov word ptr [sysold+2],es ;and save it
mov dx,offset sysint
push ds
mov ax,cs
mov ds,ax
mov ax,2508h